package com.sxkf.template.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.Banner;
import com.sxkf.template.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* 轮播图表(t_banner)表控制层
*
* @author zgc
*/
@Api(tags="轮播图模块管理")
@RestController
@RequestMapping("/banner")
public class BannerController {
/**
* 服务对象
*/
    @Resource
    private BannerService bannerService;

    @ApiOperation("查询轮播图")
    @GetMapping("/list")
    public R<List<Banner>> list(){
        return R.success(bannerService.list(new LambdaQueryWrapper<Banner>().orderByAsc(Banner::getSort)));
    }

    @ApiOperation("新增轮播图")
    @PostMapping("/add")
    public R<?> add(@RequestBody Banner banner){
        bannerService.save(banner);
        return R.success();
    }

    @ApiOperation("删除轮播图")
    @PostMapping("/delete")
    public R<?> delete(@RequestParam String id){
        bannerService.removeById(id);
        return R.success();
    }

    @ApiOperation("修改轮播图")
    @PostMapping("/update")
    public R<?> update(@RequestBody Banner banner){
        bannerService.updateById(banner);
        return R.success();
    }
}
